<template>
  <div class="app-container">
    <!-- 查询表单-->
    <!--element-ui的 date-picker组件默认绑定的时间值是默认世界标准时间，和中国时间差8小时
          设置 value-format="yyyy-MM-dd HH:mm:ss" 改变绑定的值-->
    <div id="content">
      <i class="el-icon-menu">筛选</i>
      <p />
      <el-form :inline="true" :model="regularQuery" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input
            v-model="regularQuery.name"
            placeholder="输入定期理财产品名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker
            v-model="regularQuery.startTime"
            type="datetime"
            placeholder="选择开始日期"
            default-time="00:00:00"
          />
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="regularQuery.endTime"
            type="datetime"
            placeholder="选择结束日期"
            default-time="00:00:00"
          />
        </el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getQueryList()"
          >筛选</el-button
        >
        <el-button type="default" @click="resetData()">清空筛选条件</el-button>
      </el-form>
      <el-row>
        <el-col
          ><div class="grid-content bg-purple">
            <i class="el-icon-menu">未上架定期理财产品列表</i>
          </div></el-col
        >
        <el-col><div class="grid-content bg-purple-light"></div></el-col>

        <el-col
          ><div class="grid-content bg-purple add">
            <router-link :to="{ path: '/list/regular' }">
              <el-button type="primary" icon="el-icon-notebook-2"
                >返回已上架产品列表</el-button
              >
            </router-link>
          </div></el-col
        >
      </el-row>
      <p />
      <!--表格-->
      <el-table
        v-loading="listLoading"
        :data="list"
        @selection-change="handleSelectionChange"
        element-loading-text="数据加载中"
        border
        fit
        stripe
        highlight-current-row
        style="width: 100%"
      >
        <!--数据展示- class="head_pic"-->
        <el-table-column
          type="selection"
          width="65"
          align="center"
        ></el-table-column>
        <el-table-column prop="fid" label="产品id" width="60" align="center" />
        <el-table-column
          prop="fname"
          label="产品名称"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column label="即将开售展示图片" width="180" align="center">
          <template slot-scope="scope">
            　　　　<img :src="scope.row.picUrl" width="40" height="40" />
            　　</template
          >
          ></el-table-column
        >
        <el-table-column label="售罄展示图片" width="130" align="center">
          <template slot-scope="scope">
            　　　　<img :src="scope.row.endPicUrl" width="40" height="40" />
            　　</template
          >
          ></el-table-column
        >
        <el-table-column
          prop="purchasing"
          label="购买需求"
          width="160"
          align="center"
        />
        <el-table-column
          prop="isHotName"
          label="是否明星产品"
          width="160"
          align="center"
        />

        <el-table-column
          prop="sellStartTime"
          label="开售时间"
          width="170"
          align="center"
        />
        <el-table-column
          prop="sellEndTime"
          label="停售时间"
          width="170"
          align="center"
        />
        <el-table-column label="操作" width="500" align="center">
          <template slot-scope="scope">
            <router-link :to="'/list/edit/' + scope.row.fid">
              <el-button type="primary" size="mini" icon="el-icon-edit"
                >编辑</el-button
              >
            </router-link>
            <template v-if="scope.row.isHot == 1">
              <el-button
                type="danger"
                size="mini"
                icon="el-icon-delete"
                @click="updateIsHot(scope.row.fid, 2)"
                >取消明星产品</el-button
              >
            </template>
            <template v-if="scope.row.isHot == 2">
              <el-button
                type="success"
                size="mini"
                icon="el-icon-delete"
                @click="updateIsHot(scope.row.fid, 1)"
                >设为明星产品</el-button
              >
            </template>
            <el-button
              type="success"
              size="mini"
              icon="el-icon-remove"
              @click="recoverDataById(scope.row.fid)"
              >上架</el-button
            >

            <el-button
              type="danger"
              size="mini"
              icon="el-icon-delete"
              @click="removeDataById(scope.row.fid)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        :current-page="page"
        :page-size="limit"
        :total="total"
        background
        style="padding: 30px 0; text-align: center"
        layout="total, prev, pager, next, jumper"
        @current-change="getList"
      />
    </div>
  </div>
</template>
<script>
//引入调用slideShow.js文件
import regularApi from "@/api/regular";

export default {
  //写核心代码位置
  // data:{
  // },
  data() {
    //定义变量和初始值
    return {
      listLoading: true, // 是否显示loading信息
      list: null, //查询之后接口返回集合
      page: 1, //当前页
      limit: 10, //每页记录数
      total: 0, //总记录数
      regularQuery: {
        //条件封装对象
        // name: "",
        // startTime: "",
        // endTime: "",
      },
      checkList: [],
    };
  },
  created() {
    //页面渲染之前执行，一般调用methods定义的方法
    //调用
    this.getList();
  },
  mounted() {
    this.listLoading = false;
  },
  methods: {
    //取消或者确定明星产品
    updateIsHot(id, isHot) {
      this.regularQuery.isHot = isHot;
      this.regularQuery.fid = id;
      regularApi.updateIsHot(this.regularQuery).then((response) => {
        //提示信息
        this.$message({
          type: "success",
          message: "修改明星产品状态成功!",
        });
        if (response.code == 200) {
          //回到列表页面 路由跳转
          // this.$router.push({ path: "/list/regular" });
          this.getList();
        }
      });
    },
    //创建具体的方法，调用slideShow.js定义的方法
    //获取轮播图列表的方法,默认是第一页
    getList(page = 1) {
      this.page = page;
      this.regularQuery.page = page;
      this.regularQuery.size = this.limit;
      this.regularQuery.status = 2;
      this.regularQuery.isHot = 3;
      regularApi.getRegularListPage(this.regularQuery).then((response) => {
        //请求成功
        //response接口返回的数据
        this.list = response.data.list;
        this.total = response.data.total;
      });
    },
    getQueryList(page = 1) {
      this.page = page;
      this.regularQuery.page = this.page;
      this.regularQuery.size = this.limit;
      this.regularQuery.status = 2;
      regularApi.getQueryRegularListPage(this.regularQuery).then((response) => {
        //请求成功
        //response接口返回的数据
        this.list = response.data.list;
        this.total = response.data.total;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      //获取所有选中项的gh(工号)属性的值
      this.checkList = selection.map((item) => item.fid);
    },
    resetData() {
      //清空的方法
      //表单输入项数据清空
      this.regularQuery = {};
      this.checkList = [];
      //查询所有讲师数据
      this.getList();
      this.$message({
        type: "success",
        message: "清空成功!",
      });
    },
    //上架产品的方法
    recoverDataById(id) {
      this.checkList.push(id);
      this.$confirm(
        "此操作将会上架产品,是否继续?",
        "提示",

        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          //点击确定，执行then方法
          //调用删除的方法
          regularApi.recoverRegular(this.checkList).then((response) => {
            //删除成功
            //提示信息
            this.checkList = [];
            this.$message({
              type: "success",
              message: "产品上架成功!",
            });
            //回到列表页面
            // this.$router.push({ path: "/list/slideShow" });
            this.getList();
          });
        })
        .catch((e) => {
          this.checkList = [];
          this.$message({
            type: "info",
            message: "已取消下架操作!",
          });
        }); //点击取消，执行catch方法
    },
    //删除轮播图的方法
    removeDataById(id) {
      this.checkList.push(id);
      this.$confirm(
        "此操作将会彻底删除产品数据,请问是否继续?",
        "提示",

        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          //点击确定，执行then方法
          //调用删除的方法
          regularApi.removeRegular(this.checkList).then((response) => {
            //删除成功
            //提示信息
            this.checkList = [];
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            //回到列表页面
            this.getList();
          });
        })
        .catch((e) => {
          this.checkList = [];

          this.$message({
            type: "info",
            message: "已取消删除!",
          });
        }); //点击取消，执行catch方法
    },
  },
};
</script>
<style>
#content {
  width: 80%;
  margin: 0 auto;
}
.el-row .el-col-24 {
  width: 250px;
}
.el-col-24:nth-child(3),
.el-col-24:nth-child(4) {
  float: right;
}
</style>